package chapter5.practice;

import java.util.Scanner;

public class Student {
    private String name;
    private int age;
    private String gender;
    private String phone;
    private String address;
    private String email;

    //无参构造
    public Student(){}
    //全参构造
    public Student(String name, int age, String gender, String phone, String address, String email) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.phone = phone;
        this.address = address;
        this.email = email;
    }

    public void play() {
        System.out.println("又到了每日最快乐的娱乐时间...");
    }

    public void sleep() {
        System.out.println("玩累该睡觉了");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public static void main(String[] args) {
        Student[] students = new Student[3];
        Student student = new Student("leemz", 37, "男", "18500137564", "beijing", "lmz8860@gmail.com");
        Student student2 = new Student("cwh", 35, "女", "13500137564", "hebei", "cwh@163.com");
        Student student3 = new Student("zhangsan", 20, "男", "13850132564", "henan", "zhangsan@126.com");
        students[0] = student;
        students[1] = student2;
        students[2] = student3;
        System.out.println("请选择查询学生的方式, 1:按姓名  2:电子邮件  3:地址");
        Scanner scanner = new Scanner(System.in);
        int select = scanner.nextInt();
        String name = "";
        String email = "";
        String address = "";
        switch (select) {
            case 1:
                System.out.println("请输入要查询的姓名:");
                name = scanner.next().trim();
                findByName(students, name);
                break;
            case 2:
                System.out.println("请输入要查询的email:");
                email = scanner.next();
                findByEmail(students, email);
                break;
            case 3:
                System.out.println("请输入要查询的地址:");
                address = scanner.next();
                findByAddress(students, address);
                break;
        }
    }

    private static void findByName(Student[] students, String name) {
        for (Student stu : students) {
            if(stu.getName().equals(name)) {
                System.out.println("找到学生:" + name);
                return;
            }
        }
        System.out.println("未找到该学生");
    }
    private static void findByEmail(Student[] students, String email) {
        for (Student stu : students) {
            if(stu.getEmail().equals(email)) {
                System.out.println("找到学生:" + stu.getName());
                return;
            }
        }
        System.out.println("未找到该学生");
    }
    private static void findByAddress(Student[] students, String address) {
        for (Student stu : students) {
            if(stu.getAddress().equals(address)) {
                System.out.println("找到学生:" + stu.getName());
                return;
            }
        }
        System.out.println("未找到该学生");
    }
}
